package net.alt;

import gui.panel_new.evaluation.professor.StudentMarksPanel;
import misc.ExportDataPreferences;
import model.eval.Test;
import net.TCPThread;
import net.UserData;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Jose Martin Rozanec;
 * @deprecated;
 */
public class Server {
    private ServerSocket serverSocket;
    private List<TCPThread> threads;

    private StudentMarksPanel studentMarksPanel;

    /**
     * @param port
     */
    public Server(int port) {
        threads = new ArrayList<TCPThread>();
        /* create socket server and wait for connection requests */
        try {
            serverSocket = new ServerSocket(port);
            System.out.println("Server waiting for client on port " + serverSocket.getLocalPort());

            while (true) {
                Socket socket = serverSocket.accept();  // accept connection
                System.out.println("New client asked for a connection");
                TCPThread tcpThread = new TCPThread(socket, new Test(), 0, new ArrayList<UserData>(), studentMarksPanel,new ExportDataPreferences());    // make a thread of it
                System.out.println("Starting a thread for a new Client");
                tcpThread.start();
                threads.add(tcpThread);
            }
        }
        catch (IOException e) {
            System.out.println("Exception on new ServerSocket: " + e);
        }
    }
}

